package com.xxgc.eow.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.xxgc.eow.result.Result;

import java.time.LocalDateTime;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.xxgc.eow.service.ITreatmentService;
import com.xxgc.eow.entity.Treatment;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 企业待遇表 前端控制器
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-22
 */
@Tag(name = "企业待遇表")
@RestController
@RequestMapping("/treatment")
public class TreatmentController {

    @Resource
    private ITreatmentService treatmentService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "查询所有接口", description = "查询企业待遇表所有数据")
    @SaIgnore
    @GetMapping
    public Result<List<Treatment>> findAll() {
        return Result.ok(treatmentService.getAllTreatment());
    }

    /**
     * 根据id查询数据接口
     * @param companyId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "根据企业id查询数据接口", description = "根据企业id查询")
    @Parameters({
            @Parameter(name = "companyId",description = "根据企业id",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/{companyId}")
    public Result<List<Treatment>> findOne(@PathVariable Integer companyId) {
        return Result.ok(treatmentService.getAllByCompanyId(companyId));
    }

    /**
     * 分页查询接口
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "分页查询接口", description = "分页查询")
    @Parameters({
            @Parameter(name = "pageNum",description = "页码",example="1",required = true,in=ParameterIn.QUERY),
            @Parameter(name = "pageSize",description = "每页多少条",example="10",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/page")
    public Result<Page<Treatment>> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        QueryWrapper<Treatment> queryWrapper = new QueryWrapper<>();
        return Result.ok(treatmentService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /**
     * 新增接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "新增接口", description = "新增接口")
    @SaIgnore
    @PostMapping("/save")
    public Result save(@RequestBody Treatment treatment) {
        treatmentService.addTreatment(treatment);
        return Result.ok();
    }

    /**
     * 更新接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "更新接口", description = "根据旧的待遇ID和企业Id")
    @SaIgnore
    @PostMapping("/update")
    public Result update(@RequestBody Treatment treatment,int oldTreatmentId) {
        treatmentService.updatTreatment(treatment,oldTreatmentId);
        return Result.ok();
    }

    /**
     * 删除接口
     * @param companyId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "删除接口", description = "通过companyId和treatmentId删除")
    @Parameters({
            @Parameter(name = "companyId",description = "companyId",required = true,in=ParameterIn.QUERY),
            @Parameter(name = "treatmentId",description = "treatmentId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/del")
    public Result delete( @Parameter Integer companyId, @Parameter int treatmentId) {
        Treatment treatment = new Treatment();
        treatment.setCompanyId(companyId);
        treatment.setTreatmentTypeId(treatmentId);
        treatment.setDestroyTime(LocalDateTime.now());
        treatment.setTip(1);
        treatmentService.delTreatment(treatment);
        return Result.ok();
    }

//    /**
//     * 批量删除接口
//     * @param ids
//     * @return
//     */
//    @ApiOperationSupport(author = "Mr.Abel")
//    @Operation(summary = "批量删除接口", description = "批量删除接口")
//    @SaIgnore
//    @PostMapping("/del/batch")
//    public Result deleteBatch(@RequestBody List<Integer> ids) {
//
//        return Result.ok();
//    }
}